package com.zhuiyun.project.api.plan.fitnessPlanActionCount.service.impl;

import com.zhuiyun.project.api.plan.fitnessPlanAction.entity.FitnessPlanAction;
import com.zhuiyun.project.api.plan.fitnessPlanAction.mapper.FitnessPlanActionMapper;
import com.zhuiyun.project.api.plan.fitnessPlanAction.model.FitnessPlanActionModel;
import com.zhuiyun.project.api.plan.fitnessPlanAction.service.FitnessPlanActionService;
import com.zhuiyun.project.api.plan.fitnessPlanActionCount.entity.FitnessPlanActionCount;
import com.zhuiyun.project.api.plan.fitnessPlanActionCount.mapper.FitnessPlanActionCountMapper;
import com.zhuiyun.project.api.plan.fitnessPlanActionCount.model.FitnessPlanActionCountModel;
import com.zhuiyun.project.api.plan.fitnessPlanActionCount.service.FitnessPlanActionCountService;
import com.zhuiyun.project.api.plan.fitnessType.entity.FitnessType;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.errorCode.EmErrorCode;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.pageUtil.MybatisPageHelper;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import com.zhuiyun.project.utils.pageUtil.PageResult;
import com.zhuiyun.project.utils.validator.ValidatorUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName FitnessActionServiceImpl
 * @Description TODO
 * @Author ys
 * @Date 2023/11/2 9:01
 **/
@Service
public class FitnessPlanActionCountServiceImpl implements FitnessPlanActionCountService {
    @Resource
    private FitnessPlanActionCountMapper fitnessPlanActionCountMapper;
    /**
     * @Author 杨珅
     * @Description todo 健身计划动作分页查询
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public PageResult selectAll(PageRequest pageRequest, Integer planActionId) {
        MybatisPageHelper.startPage(pageRequest);// 使用MybatisPageHelper实现分页功能，设置分页信息
        List<FitnessPlanActionCountModel> PlanActionList = fitnessPlanActionCountMapper.selectAll(pageRequest,planActionId);// 调用ArticleReviewMapper的getArticle方法查询文章列表\
        return MybatisPageHelper.getPageResult(PlanActionList);
    }
//    /**
//     * @Author 杨珅
//     * @Description todo 根据目的id全查标签
//     * @Date 2023/11/2 9:28
//     * @Return  * @param null
//     */
//    @Override
//    public PageResult selectTypes(PageRequest pageRequest, Integer fitnessPurposeId) {
//        MybatisPageHelper.startPage(pageRequest);// 使用MybatisPageHelper实现分页功能，设置分页信息
//        List<FitnessType> TypeList = fitnessPlanActionMapper.selectTypes(pageRequest,fitnessPurposeId);// 调用ArticleReviewMapper的getArticle方法查询文章列表\
//        return MybatisPageHelper.getPageResult(TypeList);
//    }
//
    /**
     * @Author 杨珅
     * @Description todo 健身计划动作新增
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public CommonResult insertFitnessPlanActionCount(FitnessPlanActionCount fitnessPlanActionCount)throws CommonException {
        if (ValidatorUtil.ValidationObject(fitnessPlanActionCount)){
            fitnessPlanActionCount.setCreateTime(new Date());
            fitnessPlanActionCount.setUpdateTime(new Date());
            int i = fitnessPlanActionCountMapper.insertFitnessPlanActionCount(fitnessPlanActionCount);
            if (i >= 1) {
                return CommonResult.ok(EmErrorCode.SAVE_OK);
            }else {
                return CommonResult.ok(EmErrorCode.SAVE_ERROR);
            }
        } else{
            return CommonResult.ok(EmErrorCode.SAVE_ERROR);
        }
    }
    /**
     * @Author 杨珅
     * @Description todo 健身计划动作修改
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public CommonResult updateFitnessPlanActionCount(FitnessPlanActionCount fitnessPlanActionCount)throws CommonException {
        if (ValidatorUtil.ValidationObject(fitnessPlanActionCount)){
            int i = fitnessPlanActionCountMapper.updateFitnessPlanActionCount(fitnessPlanActionCount);
            if (i >= 1) {
                return CommonResult.ok(EmErrorCode.UPDATE_OK);
            }else {
                return CommonResult.ok(EmErrorCode.UPDATE_ERROR);
            }
        } else{
            return CommonResult.ok(EmErrorCode.UPDATE_ERROR);
        }
    }
    /**
     * @Author 杨珅
     * @Description todo 健身计划动作删除
     * @Date 2023/11/2 9:28
     * @Return  * @param null
     */
    @Override
    public CommonResult deleteFitnessPlanActionCount(FitnessPlanActionCount fitnessPlanActionCount) {
        return CommonResult.ok(fitnessPlanActionCountMapper.deleteFitnessPlanActionCount(fitnessPlanActionCount));
    }
}
